package com.jz.yanshe.ui;

import android.content.Context;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.jz.yanshe.base.BaseActivity;

import butterknife.BindView;
import com.jz.yanshe.R;
/**
 * Created by Administrator on 2018/3/16.
 */

public class MessageActivity extends BaseActivity {

    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;


    @Override
    protected void initViews() {
        mViewPager.setAdapter(new MallPageAdapter(this, getSupportFragmentManager()));
        mTabLayout.setupWithViewPager(mViewPager);
//        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mViewPager.setCurrentItem(0);
        mTabLayout.getTabAt(0).select();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_message;
    }


    class MallPageAdapter extends FragmentPagerAdapter {
        private static final int PAGE_COUNT = 2;

        private Context mContext;

        public MallPageAdapter(Context context, FragmentManager fm) {
            super(fm);
            this.mContext = context;
        }

        @Override
        public Fragment getItem(int position) {
            Fragment f = null;
            switch (position) {
                case 0:
                    f = new MessageFragment();
                    break;
                case 1:
                    f = new MessageFriendFragment();
                    break;
                default:
                    f = new MessageFragment();
                    break;
            }
            return f;
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "会员通知";
                case 1:
                    return "好友浏览";
                default:
                    return "";
            }
        }
    }
}
